
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Segment如何实现扩容 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Segment如何实现扩容 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在 Java 7 及更早版本中，`ConcurrentHashMap` 是如何实现并发控制的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它使用 `Segment` 结构来实现并发控制。每个 `Segment` 实际上是一个独立的哈希表，并且每个 `Segment` 使用独立的锁来控制对该段的并发访问。</div>
          </div>
          <div class="card-source">来源: 文档引言部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在 Java 7 的 `ConcurrentHashMap` 中，什么条件会触发单个 `Segment` 的扩容操作？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当 `Segment` 中的元素数量达到一个特定的阈值时会触发扩容，这个阈值通常是负载因子与 `Segment` 容量的乘积。</div>
          </div>
          <div class="card-source">来源: 1. Segment 扩容的基本原理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">请描述 `ConcurrentHashMap` 的 `Segment` 在扩容时，元素是如何从旧表迁移到新表的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">扩容时会遍历旧 `Segment` 中的所有桶，将每个桶中的元素（通常是链表）重新计算其哈希值在新表中的位置，然后将该元素插入到新表的对应桶中。</div>
          </div>
          <div class="card-source">来源: 2.3 重新分配和迁移元素</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Java 7 `ConcurrentHashMap` 的分段锁（Segment Locking）在扩容时如何工作以保证并发性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在对一个 `Segment` 进行扩容时，只有该 `Segment` 自身会被锁定。这意味着其他线程对其他 `Segment` 的并发操作不会受到影响，从而保证了整体的并发性能。</div>
          </div>
          <div class="card-source">来源: 3. 锁机制的扩容</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">`ConcurrentHashMap`（Java 7）的分段扩容设计对整体性能有何积极影响？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">由于扩容操作只锁定当前正在扩容的 `Segment`，其他线程仍然可以并发地访问和操作其他 `Segment`。这种设计允许在高并发访问的同时进行扩容，从而最大限度地减少了对整体性能的影响。</div>
          </div>
          <div class="card-source">来源: 4. 扩容对性能的影响</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">当 `ConcurrentHashMap` 的一个 `Segment` 进行扩容时，其新容量通常是如何计算的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在扩容时，新的容量通常是当前 `Segment` 容量的两倍，以确保有足够的空间存储新元素并减少哈希冲突。</div>
          </div>
          <div class="card-source">来源: 2.1 计算新容量</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
